package controle.service;

import java.io.Serializable;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.text.ParseException;

import java.util.ArrayList;



public class UtilisateurService implements Serializable 

{
		static ConnectionBDService conn = new ConnectionBDService(); 
		private static final long serialVersionUID = 1L;
		private String login,passeword,nom,prenom,adresse,telephone,email; 
		private int administrateur; 
		private static ArrayList<UtilisateurService> utilisateurlist = new ArrayList<UtilisateurService>();
		
		public static  String[][] getUtilisateur() throws SQLException
		{
			String [][]detail = new String[0][8];
			String sqlCount = "select count(*) from  utilisateur";
			String sql = "select * from  utilisateur order by LOGIN";
			Statement stmt = conn.getConn().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
			ResultSet rs = stmt.executeQuery(sqlCount);
			int count = 0;
			if(rs.next()){
				count = rs.getInt(1);
			}
			detail = new String[count][8];
			rs = stmt.executeQuery(sql);
			int i = 0;
			while(rs.next()){
				for(int j = 0; j < 8; j++){
					detail[i][j] = rs.getString(j+1);
				}
				i++;
			}
			conn.closeConn();
			return detail;
		}
		
		public static  String[][] getUtilisateurParAdministrateur(String administrateur) throws SQLException
		{
			String [][]detail = new String[0][8];
			String sqlCount = "select count(*) from utilisateur where administrateur='"+administrateur+"';";
			String sql = "select * from utilisateur where administrateur='"+ administrateur+ "' order by LOGIN;";
			Statement stmt = conn.getConn().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
			ResultSet rs = stmt.executeQuery(sqlCount);
			int count = 0;
			if(rs.next()){
				count = rs.getInt(1);
			}
			detail = new String[count][8];
			rs = stmt.executeQuery(sql);
			int i = 0;
			while(rs.next()){
				for(int j = 0; j < 8; j++){
					detail[i][j] = rs.getString(j+1);
				}
				i++;
			}
			conn.closeConn();
			return detail;
		}
		
			
		
		public String getLogin()
		{
			return login;
		}
		
		public void setLogin(String login)
		{
			this.login = login;
		}
		
		
		public String getPasseword()
		{
			return passeword;
		}
		
		public void setPasseword(String passeword)
		{
			this.passeword = passeword;
		}
		
		
		public String getNom()
		{
			return nom;
		}
		
		public void setNom(String nom)
		{
			this.nom = nom;
		}
		
		public String getPrenom()
		{
			return prenom;
		}
		
		public void setPrenom(String prenom)
		{
			this.prenom = prenom;
		}
		
		
		public String getAdresse()
		{
			return adresse;
		}
		
		public void setAdresse(String adresse)
		{
			this.adresse = adresse;
		}
		
		
		public String getTelephone()
		{
			return telephone;
		}
		
		public void setTelephone(String telephone)
		{
			this.telephone = telephone;
		}
		
		public String getEmail()
		{
			return email;
		}
		
		public void setEmail(String email)
		{
			this.email = email;
		}

		
		public int getAdministrateur()
		{
			return administrateur;
		}
		
		public void setAdministrateur(int administrateur)
		{
			this.administrateur = administrateur;
		}
}

	




